<!DOCTYPE html>
<head> 
    <meta charset="utf-8"> 
    <title>查询数据</title>  
</head>
<?php
	//连接数据库
	date_default_timezone_set('Asia/Shanghai');
	$conn = @mysql_connect("localhost","root","sdata007");
	if(!$conn){
		die("连接数据库失败：". mysql_error());
	}else{
		echo "连接数据库成功";
		echo "<br>";
	}
	//选择数据库
	mysql_select_db("testdb",$conn);
	mysql_query("set names 'utf8'");
	$password = md5("sppasdf");
	$regdate = time();
	$sql = "SELECT * FROM myuser";
	$result = mysql_query($sql);
	if(!mysql_query($sql,$conn)){
		echo "操作失败：" . mysql_error();
	}else{
		echo "操作成功！";	
		echo "<br>";
	}
	//读取数据
	while($row = mysql_fetch_array($result)){
		$got[] = array(
			"username"=>$row['username'],
			"password"=>$row['password'],
			"email"=>$row['email'],
			"regdate"=> date("Y-m-d H:i:s",$row['regdate']),
		);
	}
	$jsonArr = array(
			'flag' => 'SUCCESS',
			'msg' => '查询成功',
			'data' => $got
		);
	echo json_encode($jsonArr);
	
	mysql_close( $conn );
?>